Fix missing return value check in EVP_PKEY_sign_init#199
Conversation
THROW(EVP_PKEY_sign_init(ctx)) treats any non-zero return as success, including negative error codes (-2 = operation not supported). The verify() path already checks == 1 correctly; bring sign() in line. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Note: PR #191 now includes this fix. The If #191 is merged first, this PR becomes redundant. If this PR is merged first, #191 will pick up the |
|
Note: This fix is fully subsumed by #191, which replaces all If #191 is merged first, this PR can be closed. If you prefer this smaller scoped fix first, #191 will need a trivial rebase on the |
What
Check
EVP_PKEY_sign_init(ctx) == 1instead of bare truthiness insign()on OpenSSL 3.x.Why
THROW(EVP_PKEY_sign_init(ctx))treats any non-zero return as success. OpenSSL EVP init functions return 1 on success but can return negative values on error (-2 = not supported). A negative value is truthy in C, so the code would silently proceed past a failed init. Theverify()function already checks== 1correctly at line 1518 — this bringssign()into consistency.How
One-character change:
THROW(EVP_PKEY_sign_init(ctx))→THROW(EVP_PKEY_sign_init(ctx) == 1).Testing
Full test suite passes. The bug is unlikely to trigger in practice (EVP_PKEY_sign_init returns 1 for RSA keys), but the code is technically wrong and inconsistent with verify().
🤖 Generated with Claude Code
Quality Report
Changes: 1 file changed, 1 insertion(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline